package com.yatube.nhx.api.controller.frontend;

import com.yatube.nhx.result.R;
import com.yatube.nhx.system.entities.ProjectTag;
import com.yatube.nhx.system.service.ProjectTagService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author Created with IDEA
 * @description --
 * @date 2024-04-25 23:03
 */
@Tag(name = "项目标签接口")
@RestController
@RequestMapping("project/tag")
public class ProjectTagApiController {

    @Resource
    private ProjectTagService projectService;

    @PostMapping("add")
    public R add(@RequestBody ProjectTag project){
        boolean result = projectService.save(project);
        if(!result){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable("id") Long id){
        projectService.removeById(id);
        return R.ok();
    }

    @PutMapping("update")
    public R update(@RequestBody ProjectTag tag){
        projectService.updateById(tag);
        return R.ok();
    }

    // 详情
    @GetMapping("{id}")
    public R getById(@PathVariable Long id){
        ProjectTag tag = projectService.getById(id);
        return R.ok(tag);
    }

    // 分页
    @GetMapping("list")
    public R list(){
        return R.ok(projectService.list());
    }

}
